package com.nicy.dream.biz;

import com.nicy.dream.common.AutoIdempotent;
import com.nicy.dream.common.TokenService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @description:
 * @projectName:dream
 * @see:com.nicy.dream.biz
 * @author:NicyYe
 * @createTime:2021/2/22 9:50
 * @version:1.0
 */
@Api(tags = "Token测试控制器")
@RestController
@RequestMapping("/token")
public class TokenController {

    @Resource
    private TokenService tokenService;

    @ApiOperation(value = "获取token")
    @PostMapping("/get")
    public String getToken(){
        String token = tokenService.createToken();
        if(!StringUtils.isEmpty(token)){
            return token;
        }

        return "";
    }

    @ApiOperation(value = "重复提交")
    @AutoIdempotent
    @PostMapping("/test")
    public String test(HttpServletRequest request){
        String token = request.getHeader("token");
        System.out.println(token);
        String result = "";
        //String token = tokenService.createToken();
        //if(!StringUtils.isEmpty(token)){
            //tokenService.checkToken()
        //}

        return "已经调用重复提交接口";
    }
}
